package automatica.autoprove;


import java.io.File;
import ui.Utility;
import ui.ShowFrame;
import com.maplesoft.openmaple.Engine;

public class AutoProve {
	
	private CallBacks callback;
	
	//
	public AutoProve(Engine engine, CallBacks callback, String resultPath, String xslPath, String outputPath, String name, String proofPath){
		this.callback = callback;
		Map2GEOTHER normalForm = new Map2GEOTHER(resultPath, xslPath, outputPath);                                    
		for(int i = 0; i < normalForm.getPredicate4GEOTHER().size(); i++){
			//MapleLink prove = new MapleLink(engine, "PROBLEM_" + count + (i+1==1?null:"_"+i+1),normalForm.getPredicate4GEOTHER().get(i)+(i==0?"":"#"+i));			
			new MapleLink(engine, name==null?"demo":Utility.deleteSpace(name).replace(".", "")+(i+1),normalForm.getPredicate4GEOTHER().get(i));
		}
		showProof(proofPath, "auto-proof in GEOTHER: " + name);
	}

	public AutoProve(Engine engine, CallBacks callback, String data, String name, String proofPath){
		this.callback = callback;
		Map2GEOTHER normalForm = new Map2GEOTHER(data);                                    
		for(int i = 0; i < normalForm.getPredicate4GEOTHER().size(); i++){
			new MapleLink(engine, name==null?"demo":name+(i+1),normalForm.getPredicate4GEOTHER().get(i));
		}
		showProof(proofPath, "auto-proof in GEOTHER: " + name);
	}
	

	
	
	public void showProof(String proofPath, String title){
		File proofFile = new File(proofPath);
		/*
		if(proofFile.exists()){
			proofFile.delete();
		}*/
		Utility.saveFile(null, "<html><head><style type='text/css'> span.text {color:black; font-family:verdana;font-size:110%;} span.status{color:rgb(160,160,160);}</style></head><body><div>" + callback.getOutput() + "</div>" +
				//"<script type='text/javascript'>document.scroll(0,document.body.scrollHeight);</script>" +
				"</body></html>", proofFile);
		ShowFrame showFrame = new ShowFrame();
		showFrame.show(null,null,proofFile.toString());
		showFrame.setVisible(true);
		showFrame.setTitle(title);
		
	}

	
    
 

}
